package com.woniuxy.oa.web;

import com.woniuxy.oa.entity.ResponseVO;
import com.woniuxy.oa.entity.Signin;
import com.woniuxy.oa.service.SigninService;
import com.woniuxy.oa.util.OaUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Mr X
 */
@RequestMapping("signin")
@RestController
@CrossOrigin("*")
public class SigninController {
    private static final Integer rhours = 9;
    @Autowired
    private SigninService signinService;

    @PostMapping("add")
    public ResponseVO add(Signin signin) {
        Integer hours = Integer.parseInt(OaUtil.getNow().substring(11, 13));
        if (hours > rhours) {
            return new ResponseVO("500", "打卡失败", null);
        }
        signinService.add(signin);
        return new ResponseVO("200", "打卡成功", null);
    }

//    @GetMapping("list")
//    public ResponseVO list(@SessionAttribute("emp") Emp emp) {
//        List<Signin> signinList = signinService.getByEmpId(emp.getId());
//        List<String> upTime = new ArrayList<>();
//        for (Signin signin : signinList) {
//            upTime.add(signin.getUpTime());
//        }
//        return new ResponseVO("200", "查询成功", upTime);
//    }
}
